$(document).ready(function() {

    //var requestUrl="192.168.1.15:8092/"
     let requestUrl="http://127.0.0.1:8092/"
    $("#login").click(function () {

        let user_login_name = $('#user_login_name').val();
        let user_login_passwd = $('#user_login_passwd').val();
        let data = {user_name:user_login_name,user_passwd:user_login_passwd}
        data = JSON.stringify(data);
        $.ajax({

            type:"POST",
            url:requestUrl+"login",
            data:data,
            dataType:'json',//"xml", "html", "script", "json", "jsonp", "text".
            contentType:"application/json;charset=UTF-8",
            beforeSend:function(){

            },

            success:function(data){

                //let  jsonData = eval("(" + data + ")");

                if(data.result_code==0){

                    layer.msg(data.result_mes);

                    setTimeout(function () {
                        window.location.replace(requestUrl+"goHomePage");
                        //页面层

                    },1000);


                }else{
                    layer.msg(data.result_mes);

                }

            }   ,

            complete: function(XMLHttpRequest, textStatus){
                //alert(XMLHttpRequest.responseText);
                //alert(textStatus);
                //HideLoading();

            },
            //调用出错执行的函数
            error: function(){
                layer.msg("系统出错");
            }
        });

    });


    $("#register").click(function () {

        let user_register_name = $('#user_register_name').val();
        let user_name_test=/^\w\w{4,11}$/;//用户名必须为5-12为字母或数字
        var testResult=user_name_test.test(user_register_name);
        if(!user_register_name){
            layer.msg('用户名不能为空', function(){
                $("#user_register_name").focus();

            });
            return false;
        }else if(!testResult){

            layer.msg('用户名必须为5-12为字母或数字', function(){
                $("#user_register_name").focus();

            });
            return false;
        }
        let user_register_passwd = $('#user_register_passwd').val();
        if(!user_register_passwd){
            layer.msg('用户密码不能为空', function(){
                $("#user_register_passwd").focus();

            });
            return false;
        }
        let user_register_phone = $('#user_register_phone').val();
        let mobilereg1 = /^1[3|5|6|7|8|9][0-9]{9}$/; // 1[356789][0-9] （后面再接8位数）
        let mobilereg2 = /^14[5|7][0-9]{8}$/; // 14[57] （后面再接8位数）
        if(!user_register_phone){
            layer.msg('用户手机号不能为空', function(){
                $("#user_register_phone").focus();

            });
            return false;
        }else if (!mobilereg1.test(user_register_phone) && !mobilereg2.test(user_register_phone)) {


            layer.msg('请填写正确的手机号码', function(){
                $("#user_register_phone").focus();

            });
            return false;
        }

        let QQTest = /^[1-9][0-9]{4,14}$/;
        let user_register_QQnum = $('#user_register_QQnum').val();
        if(!user_register_QQnum){
            layer.msg('QQ号不能为空', function(){
                $("#user_register_QQnum").focus();

            });
            return false;
        }else if(!QQTest.test(user_register_QQnum)){

            layer.msg('请输入正确的QQ号', function(){
                $("#user_register_QQnum").focus();

            });
            return false;
        }




        let data = {user_name:user_register_name,user_passwd:user_register_passwd,phone:user_register_phone,QQNum:user_register_QQnum}
        data = JSON.stringify(data);
        $.ajax({

            type:"POST",
            url:requestUrl+"register",
            data:data,
            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
            contentType:"application/json;charset=UTF-8",
            beforeSend:function(){

            },

            success:function(data){
                //alert(data.result_code==0);
                if(data.result_code==0){
                    layer.msg(data.result_mes+"正在为您自动跳转……");

                    setTimeout(function () {
                        window.location.replace(requestUrl+"goHomePage");
                    },2000);

                }else{
                    layer.msg(data.result_mes);

                }

            },

            complete: function(XMLHttpRequest, textStatus){
                //alert(XMLHttpRequest.responseText);
                //alert(textStatus);
                //HideLoading();
            },
            //调用出错执行的函数
            error: function(){
                layer.msg('系统出错', function(){

                    return false;
                });
            }
        });

    });



});
